package person.crud.controller;

import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import person.crud.dao.PersonDAO;
import person.model.Person;

@Controller
@RequestMapping("/add")
public class AddController
{
    @Autowired
    PersonDAO personDAO;

    @RequestMapping(value = "/person")
    public void newPerson(HttpServletResponse response, Person person)
	    throws SQLException, IOException
    {

	if (person != null)
	{

	    if (personDAO.add(person))
	    {
		response.getWriter().println("Got new user!");

	    }
	    else
	    {
		response.getWriter().println("Add user error ! ");

	    }

	}

    }

}
